Using Checkboxes (General)The biggest gotcha for newbies is that you must set the 'value' attribute in the html <input> field to use Checkboxes with WW. By default your browser will set this to some value. Firefox uses "on" - not sure what IE or others use. You must make this a sensible value for whatever property you are setting. Using Checkboxes to set boolean fieldsHTML: <input type="checkbox" name="user.lockedOut" value="true"/> If the user checks this box, the browser will send "user.lockedOut=true" in the QueryString and action.getUser().setLockedOut(true) will be called. If the user does not check the box, the browser will not send anything, so make sure that you have initialised lockedOut to false to start with. private boolean m_lockedOut = false; public void setLockedOut(boolean lockedOut) { m_lockedOut = lockedOut; } Using Checkboxes to set a collectionOur user has a number of priviliges that are stored as a Set of strings. To use checkboxes for these, we have HTML that looks like: <input type="checkbox" name="user.priv" value="boss"/> <input type="checkbox" name="user.priv" value="admin"/> <input type="checkbox" name="user.priv" value="manager"/> Say a user checks the first 2; the browser will send the query string: user.priv=boss&user.priv=admin. OGNL will end up calling action.getUser().setPriv(String[] {"boss", "admin"}) You can write this method like: Set m_privileges = new HashSet(); public void setPriv(String[] privs) { for (int i = 0; i < privs.length; i++) { m_privileges.add(privs[i]); } } Full Detailed example:This example uses a kind-of model-driven action (see Model Driven Interceptor). The action returns a single getter for the User object whose values are populated. |